﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BUS;
namespace ManagementBooks
{
    public partial class TheLoai : Form
    {
        TheLoaiBUS theloaibus = new TheLoaiBUS();
        public TheLoai()
        {
            InitializeComponent();
        }

        private void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            int dem = e.RowIndex;

            dataGridView1.Rows[dem].Cells[0].Value = dem + 1;
        }

        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            int dem = e.RowIndex;
            tbma.Text = dataGridView1.Rows[dem].Cells["matheloai"].Value.ToString();
            tbtheloai.Text = dataGridView1.Rows[dem].Cells["tentheloai"].Value.ToString();
        }

        private void TheLoai_Load(object sender, EventArgs e)
        {
            try
            {
                DataTable dtt = new DataTable();
                dtt = theloaibus.showTL();
                dataGridView1.DataSource = dtt;
            }
            catch { }
        }

        private void bthem_Click(object sender, EventArgs e)
        {
            try
            {
                theloaibus.themTL(tbtheloai.Text);
                TheLoai_Load(sender, e);
            }
            catch { }
        }

        private void btsua_Click(object sender, EventArgs e)
        {
            try
            {
                theloaibus.suaTL(tbma.Text, tbtheloai.Text);
                TheLoai_Load(sender, e);
            }
            catch { }
        }

        private void btxoa_Click(object sender, EventArgs e)
        {
            try
            {
                theloaibus.xoaTL(tbma.Text);
                TheLoai_Load(sender, e);
            }
            catch { }
        }

        private void btthoat_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Bạn có chắc muốn thoát hay không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                this.Close();
                Dispose();
            }
        }
    }
}
